<?php

class ProductPropertyValue extends AppModel {

    public $name = 'ProductPropertyValue';
    public $useTable = 'product_property_value';
    
    
    public function getAllPropertyT1ByID($id){
        $result = $this->query("SELECT * FROM `product_property_value`, property_value
                WHERE property_value.property_value_id = product_property_value.property_value_id
                AND product_property_value.product_id = ".$id);
        $arr = array();
        if(isset($result)){
            foreach($result as $value){
                $arr[$value['property_value']['property_id']] = array('property_value_id'=>$value['product_property_value']['property_value_id']);
            }
            return $arr;
        }else return false;
        
    }
    public function getAllPropertyT2ByID($id){
        $result = $this->query("SELECT property.property_id, product_property_value.product_id, product_property_value.property_value_id 
            FROM `product_property_value`,property,property_value
            WHERE  product_property_value.property_value_id = property_value.property_value_id
            AND property_value.property_id = property.property_id
            AND property.type = 2
            AND product_property_value.product_id = ".$id." GROUP BY property_id");
        
        $arr_return = array();
        if(isset($result)){
            foreach($result as $value){
                $record = $result = $this->query("SELECT property.property_id, product_property_value.property_value_id 
                    FROM `product_property_value`,property,property_value
                    WHERE  product_property_value.property_value_id = property_value.property_value_id
                    AND property_value.property_id = property.property_id
                    AND property.type = 2
                    AND product_property_value.product_id = ".$id." AND property.property_id = ".$value['property']['property_id']);
                if(isset($record)){
                    $arr_new = array();
                    foreach($record as $val) $arr_new[] = $val['product_property_value']['property_value_id'];
                    //$arr_return[] = array($val['property']['property_id'] => $arr_new);
                    
                    $arr_return[$val['property']['property_id']] = array('property_value' => $arr_new);
                }
                
            }
            return $arr_return;
        }
        else 
            return false;
    }
   

}
